package com.ocean.web.controller.product;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.productDict.domain.OForecastType;
import com.ocean.productDict.service.IOForecastTypeService;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 预报类型维护Controller
 *
 * @author ocean
 * @date 2022-12-30
 */
@Controller
@RequestMapping("/product/forecastType")
public class OForecastTypeController extends BaseController
{
    private String prefix = "product/forecastType";

    @Autowired
    private IOForecastTypeService oForecastTypeService;

   // @RequiresPermissions("product:forecastType:view")
    @GetMapping()
    public String forecastType()
    {
        return prefix + "/list";
    }

    /**
     * 查询预报类型维护列表
     */
    //@RequiresPermissions("product:forecastType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OForecastType oForecastType)
    {
        startPage();
        List<OForecastType> list = oForecastTypeService.selectOForecastTypeList(oForecastType);
        return getDataTable(list);
    }

    /**
     * 导出预报类型维护列表
     */
    //@RequiresPermissions("product:forecastType:export")
    @Log(title = "预报类型维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OForecastType oForecastType)
    {
        List<OForecastType> list = oForecastTypeService.selectOForecastTypeList(oForecastType);
        ExcelUtil<OForecastType> util = new ExcelUtil<OForecastType>(OForecastType.class);
        return util.exportExcel(list, "预报类型维护数据");
    }

    /**
     * 新增预报类型维护
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预报类型维护
     */
    //@RequiresPermissions("product:forecastType:add")
    @Log(title = "预报类型维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OForecastType oForecastType)
    {
        return toAjax(oForecastTypeService.insertOForecastType(oForecastType));
    }

    /**
     * 修改预报类型维护
     */
    //@RequiresPermissions("product:forecastType:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OForecastType oForecastType = oForecastTypeService.selectOForecastTypeById(id);
        mmap.put("oForecastType", oForecastType);
        return prefix + "/edit";
    }

    /**
     * 修改保存预报类型维护
     */
    //@RequiresPermissions("product:forecastType:edit")
    @Log(title = "预报类型维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OForecastType oForecastType)
    {
        return toAjax(oForecastTypeService.updateOForecastType(oForecastType));
    }

    /**
     * 删除预报类型维护
     */
    //@RequiresPermissions("product:forecastType:remove")
    @Log(title = "预报类型维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oForecastTypeService.deleteOForecastTypeByIds(ids));
    }

    /**
     * 修改预报类型维护
     */
    //@RequiresPermissions("product:forecastType:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        OForecastType oForecastType = oForecastTypeService.selectOForecastTypeById(id);
        mmap.put("oForecastType", oForecastType);
        return prefix + "/detail";
    }

}
